const showModal = (opt) => {
  let option = {
    title: '提示', 
    content: '确认?',
    showCancel: true,
    cancelText: '取消',
    cancelColor: '#aaa',
    confirmText: '确定',
    confirmColor: '#3c3c3c',
  }
  if (typeof opt === 'string') {
    option.content = opt
  } else {
    option = {
      ...option,
      ...opt
    }
  }
  return new Promise((resolve, reject) => {
    wx.showModal({
      ...option,
      success: (res) => {
        if(res.confirm) {
          resolve()
        } else {
          reject()
        }
      },
    })
  })
}
const showToast = (opt, extraOpt) => {
  let option = {
    title: '成功',
    icon: 'none',
  }
  if (typeof opt === 'string') {
    option = {
      ...option,
      title: opt,
      ...extraOpt
    }
  } else {
    option = {
      ...option,
      ...opt
    }
  }
  wx.showToast(option)
}

module.exports = {
  showModal,
  showToast
}